package com.liang.collection;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionDemo {
    public static void main(String[] args) {
        Collection<String> collection =  new ArrayList<>();

        //添加方法add
        collection.add("aaa");
        collection.add("bbb");
        collection.add("ccc");
        collection.add("dddd");
        System.out.println(collection);

        //删除remove
//        method1(collection);

        //条件删除removeif
//        method2(collection);

        //包含contains
//        method3(collection);


        //清空clear
//        metjod4(collection);

        //isEmpty是否为空
        boolean empty = collection.isEmpty();
        System.out.println(empty);

        //size长度
        int size = collection.size();
        System.out.println(size);


    }

    public static void metjod4(Collection<String> collection) {
        collection.clear();
        System.out.println(collection);
    }

    public static void method3(Collection<String> collection) {
        boolean result1 = collection.contains("aaa");
        boolean result2 = collection.contains("a");
        System.out.println(result1+"----"+result2);
    }

    public static void method2(Collection<String> collection) {
        collection.removeIf(
                (String s)-> {return s.length()==3;});
        System.out.println(collection);
    }

    public static void method1(Collection<String> collection) {
        //删除remove
        collection.remove("aaa");
        System.out.println(collection);
    }
}
